package com.example.tabbar.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.tabbar.databinding.ItemRoomBinding
import com.example.tabbar.room.entity.Room

class RoomAdapter: RecyclerView.Adapter<RoomAdapter.ViewHolder>() {
    private var items: List<Room>? = null
    private var listener: ((Int) -> Unit)? = null
    fun setOnItemClickListener(listener: (Int) -> Unit) {
        this.listener = listener
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemRoomBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = items?.get(position)
        if (item != null) {
            holder.number.text = item.id.toString()
            holder.area.text = item.area
            holder.standard.text = item.standard
            holder.status.text = item.status
            holder.locCount.text = item.locCount.toString()
        }

//        holder.icon.setOnClickListener {
//            listener?.invoke(position)
//        }
    }

    override fun getItemCount(): Int {
        return items?.size ?: 0
    }

    fun setItems(items: List<Room>?) {
        this.items = items
        notifyDataSetChanged()
    }

    class ViewHolder(binding: ItemRoomBinding)
        : RecyclerView.ViewHolder(binding.root) {
        var checkbox: CheckBox = binding.isSelect
        var number:TextView = binding.number
        var area:TextView = binding.area
        var standard:TextView = binding.standard
        var status:TextView = binding.status
        var locCount:TextView = binding.Count
        var icon = binding.details
    }

}